package com.bestvike.stone.core.util.area;

import com.bestvike.linq.exception.ArgumentNullException;
import com.bestvike.stone.core.collection.KeyedCollection;
import org.springframework.util.Assert;

/**
 * 县级行政区集合
 * Created by 许崇雷 on 2018-07-28.
 */
public final class CountyCollection extends KeyedCollection<String, County> {
    private final City city;

    CountyCollection(City city) {
        Assert.notNull(city, "city can not be null");
        this.city = city;
    }

    @Override
    protected String getKeyForItem(County county) {
        return county.getCode();
    }

    @Override
    public boolean add(County county) {
        if (county == null)
            throw new ArgumentNullException("county");
        county.setCity(this.city);
        return super.add(county);
    }
}
